#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stddef.h>


struct Per{
    char name;  // 0~3
    int a;  // 4
};

void test1(){
//    int len = offsetof(struct Per, a);
}


// 嵌套结构体
struct Tea{
    char name;
    struct Per stu;
};

void test2(){
    struct Tea t = {'x','l',20};

    // 2次偏移
    int offset1 = offsetof(struct Tea,stu);
    int offset2 = offsetof(struct Per,a);

    printf("%d\n", offset1);
    printf("%d\n", offset2);

    printf("%d\n", *(int *)((char *)&t+8)  );
    printf("%d\n", ((struct Per *)((char *)&t+4))->a  );
}

// 内存对齐
// 提高访问速度  空间换时间

typedef struct _STUDENT{
    int a;  // 0-3
    char b;
    double c;
    float d;
}Student;

void main(){
    test2();
}